Repository navigation
feat(adapters): any Gymnasium environment as a game - #10
Merged
Merged
Conversation
Add one out-of-process worker that turns any registered Gymnasium environment with a Discrete action space into a Playproof game: classic control, toy text, procedurally generated suites, and text environments. Evidence is the environment's own cumulative reward, step count, termination flags, and numeric info entries, joined by a hash of the whole observation and a bounded projection of it. Reward and numeric info entries are scaled by 1000, because Playproof evidence is integer-only. The limit is stated, not hidden: a generic environment offers no privileged channel the agent cannot author, so the tier is reward-derived and verification rests on replay recomputation alone. Gymnasium exposes no generic state API. A checkpoint therefore replays from its seed, and also writes back the environment's own state attribute where one is readable. No pickle is involved. Contracts come from committed reference playthroughs on CartPole-v1 and FrozenLake-v1. Both environments ship inside Gymnasium, so the new CI job runs on a clean machine with no asset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Any registered Gymnasium environment with a
Discreteaction space becomes a PlayproofGame. One worker covers classic control, toy text, procedurally generated suites, and text environments, including third-party environments that register with Gymnasium.MultiDiscrete,MultiBinary, andBoxaction spaces are refused at boot with a readable message; a word-to-vector encoding for a continuous action is a design decision this adapter does not make for the caller.The limit is stated instead of hidden. A generic environment has no privileged channel the agent cannot author: reward,
info, and the observation are exactly what the environment hands the policy. Read the tier as reward-derived, not hidden. Verification still holds because it is replay — the verifier re-executes from the seed and the input log and recomputes every milestone.What changes
gym/worker.py— Gymnasium over the shared line-JSON worker protocol:boot,reset,step,evidence,frame,inputs,snapshot,checkpoint,restore,shutdown.adapters/gym-rpc.ts,adapters/gymnasium.ts—WorkerRpcspecialization andmakeGymnasium({ envId, seed?, kwargs?, python?, reference? }).gym/reference-cartpole.json,gym/reference-frozenlake.json— committed reference playthroughs.deriveContractreplays them and samples every milestone value and hash; no threshold or hash is written by hand.gymnasium.test.mtsandpnpm test:gym— the adapter gate, skipped with one line when Gymnasium is absent and loud underPLAYPROOF_REQUIRE_GYM=1.real-gymnasium, tsup entries, the./adapters/gymnasiumand./adapters/gym-rpcexports, asset copying, the packed-tarball requirement, the boundary prefix, README,docs/adapters.md, and a0.3.0changelog section.Design points worth review:
NOOPplus one word per action, named fromget_action_meanings()when the environment exposes it anda0…a{n-1}otherwise. A discrete space has no guaranteed idle action, soNOOPand every unknown word do not callenv.stepat all — the state is unchanged. An agent typo is not a cheat, and it must not silently advance the episode either. An environment that names its own actionNOOP, as ALE does, keeps that real action.cumulativeReward,steps,terminated,truncated, and the numericinfoentries bounded to the first 16, plusframeHashover the whole observation andframeStateover its first 8 components. Playproof evidence is integer-only, so reward, numericinfoentries, and observation components are multiplied by 1000 and rounded: reward 1.0 iscumulativeReward1000.{seed, inputs}and restore isreset(seed)plus a replay. Where the environment keeps its position in one readable attribute (statefor classic control,sfor toy text), the worker also writes a JSON copy of it and restores it directly.pickleis never used, so a checkpoint stays a plain protocol value a verifier can read.Verification
pnpm run ciin a clean worktree:The adapter gate on gymnasium 1.3.0 / numpy 2.5.2 / CPython 3.12.10:
What that gate covers:
survived-25-steps,reward-at-25-steps, andframe-at-25-steps, and is rejected only for the two it claims beyond.dispose()kills the worker and every later call fails loudly.Also checked:
python -m compileall -q gympasses, the skip line prints when Gymnasium is missing, andPLAYPROOF_REQUIRE_GYM=1turns that miss into a failure.